package cheeese.and.crackers;

import junit.framework.TestCase;

public class CheeseAndCrackersTests extends TestCase {
	
	public void testAndrew1() throws Exception {
		//Testing for UserList's addUser(User newUser)
		//Whitebox Tests
		UserList list = new UserList();
		
		User use1 = new User(" ", "test1", "test1", "test1");
		list.addUser(use1);
		assertEquals(use1, list.getUser("test1"));
		User use2 = new User("test2", " ", "test2", "test2");
		list.addUser(use2);
		assertEquals(use2, list.getUser("test2"));
		User use3 = new User("test3", "test3", " ", "test3");
		list.addUser(use3);
		assertEquals(use3, list.getUser(" "));
		User use4 = new User("test4", "test4", "test4", " ");
		list.addUser(use4);
		assertEquals(use4, list.getUser("test4"));
		User use5 = new User("test5", "test5", "test5", "test5");
		list.addUser(use5);
		assertEquals(use5, list.getUser("test5"));
		User use6 = new User("test6", "test6", "test6", "test6");
		list.addUser(use6);
		assertEquals(use5, list.getUser("test5"));
		
		//Blackbox tests
		User aTest = new User("Andrew", "achanrasmi3", "chan1", "password1");
		User bTest = new User("Dave", "dkearns6", "dave1", "password2");
		User cTest = new User("Michael", "yaoninja", "yao1", "password3");
		User dTest = new User("Chris", "cantley3", "chris1", "password4");
		list.addUser(aTest);
		list.addUser(bTest);
		list.addUser(cTest);
		list.addUser(dTest);
		assertEquals(aTest, list.getUser("chan1"));
		assertEquals(bTest, list.getUser("dave1"));
		assertEquals(cTest, list.getUser("yao1"));
		assertEquals(dTest, list.getUser("chris1"));
	}
	
	public void testAndrew2() throws Exception {
		//Testing for TaskList's addTask(Task task)
		//Whitebox Tests
		TaskList list = new TaskList();
		Task task2 = new Task(" ", "location2", "duedate2", "details2", "type2", false);
		list.addTask(task2);
		assertEquals(task2, list.getTask(" "));
		Task task3 = new Task("description3", " ", "duedate3", "details3", "type3", false);
		list.addTask(task3);
		assertEquals(task3, list.getTask("description3"));
		Task task4 = new Task("description4", "location4", "duedate4", " ", "type4", false);
		list.addTask(task4);
		assertEquals(task4, list.getTask("description4"));
		Task task5 = new Task("description5", "location5", " ", "details5", "type5", false);
		list.addTask(task5);
		assertEquals(task5, list.getTask("description5"));
		Task task6 = new Task("description6", "location6", "duedate6", "details6", " ", false);
		list.addTask(task6);
		assertEquals(task6, list.getTask("description6"));
		Task task7 = new Task("description7", "location7", "duedate7", "details7", "type7", false);
		list.addTask(task7);
		assertEquals(task7, list.getTask("description7"));
		
		//Blackbox Tests
		Task aTask = new Task("Thing1", "Place1", "Date1", "Detail1", "Kind1", false);
		Task bTask = new Task("Thing2", "Place2", "Date2", "Detail2", "Kind2", false);
		Task cTask = new Task("Thing3", "Place3", "Date3", "Detail3", "Kind3", false);
		Task dTask = new Task("Thing4", "Place4", "Date4", "Detail4", "Kind4", false);
		list.addTask(aTask);
		list.addTask(bTask);
		list.addTask(cTask);
		list.addTask(dTask);
		assertEquals(aTask, list.getTask("Thing1"));
		assertEquals(bTask, list.getTask("Thing2"));
		assertEquals(cTask, list.getTask("Thing3"));
		assertEquals(dTask, list.getTask("Thing4"));
	}
	
	public void testAndrew3() throws Exception {
		//Test method for getPassword() and setPassword() in User
		
		User user1 = new User("User One", "User1@gmail.com", "User1LoginId", "User1Password");
		User user2 = new User("User Two", "User2@gmail.com", " ", " ");
		User user3 = new User("User Three", "User3@gmail.com", "User3LoginId", "User3Password");
		User user4 = new User("User Four", "User4@gmail.com", " ", " ");
		
		assertEquals("User1Password", user1.getPassword());
		assertEquals(" ", user2.getPassword());
		assertEquals("User3Password", user3.getPassword());
		assertEquals(" ", user4.getPassword());
		
		user1.setPassword("user1 new Password");
		user2.setPassword(" ");
		user3.setPassword(" ");
		user4.setPassword("user4 new Password");
		
		assertEquals("user1 new Password", user1.getPassword());
		assertEquals(" ", user2.getPassword());
		assertEquals(" ", user3.getPassword());
		assertEquals("user4 new Password", user4.getPassword());
	}
	
	public void testAndrew4() {
		//Test method for getName() and setName() in User
		
		User user1 = new User("User One", "User1@gmail.com", "User1LoginId", "User1Password");
		User user2 = new User(" ", "User2@gmail.com", " ", " ");
		User user3 = new User("User Three", "User3@gmail.com", "User3LoginId", "User3Password");
		User user4 = new User(" ", "User4@gmail.com", " ", " ");
		
		assertEquals("User One", user1.getName());
		assertEquals(" ", user2.getName());
		assertEquals("User Three", user3.getName());
		assertEquals(" ", user4.getName());
		
		user1.setName("user1 new Name");
		user2.setName(" ");
		user3.setName(" ");
		user4.setName("user4 new Name");
		
		assertEquals("user1 new Name", user1.getName());
		assertEquals(" ", user2.getName());
		assertEquals(" ", user3.getName());
		assertEquals("user4 new Name", user4.getName());
	}
	
	public void testChris1() throws Exception {
		//Test method for getTask() in TaskList.
		
		TaskList list = new TaskList();
		
		Task task1 = new Task("description1", "location1", "duedate1", "details1", "type1", false);
		list.addTask(task1);
		Task task2 = new Task(" ", "location2", "duedate2", "details2", "type2", false);
		list.addTask(task2);
		Task task3 = new Task("WHO KNOWS", "location3", "duedate3", "details3", "type3", false);
		list.addTask(task3);
		
		assertEquals(task1, list.getTask("description1"));
		assertEquals(task2, list.getTask(" "));
		assertEquals(null, list.getTask("WELL I DON'T KNOW O.O"));
		
		
	}
	
	public void testChris2() throws Exception {
		//Test method for getLoginId() and setLoginId() in User, because those seemed like the most important.
		
		User user1 = new User("User One", "User1@gmail.com", "User1LoginId", "User1Password");
		User user2 = new User("User Two", "User2@gmail.com", " ", "User2Password");
		User user3 = new User("User Three", "User3@gmail.com", "User3LoginId", "User3Password");
		User user4 = new User("User Four", "User4@gmail.com", " ", "User4Password");
		
		assertEquals("User1LoginId", user1.getLoginId());
		assertEquals(" ", user2.getLoginId());
		assertEquals("User3LoginId", user3.getLoginId());
		assertEquals(" ", user4.getLoginId());
		
		user1.setLoginId("user1 new ID");
		user2.setLoginId(" ");
		user3.setLoginId(" ");
		user4.setLoginId("user4 new ID");
		
		assertEquals("user1 new ID", user1.getLoginId());
		assertEquals(" ", user2.getLoginId());
		assertEquals(" ", user3.getLoginId());
		assertEquals("user4 new ID", user4.getLoginId());
		
		user2.setLoginId("0");
		
		UserList list = new UserList();
		list.addUser(user1);
		list.addUser(user2);
		list.addUser(user3);
		list.addUser(user4);
		
		//woooo redundancy
		assertEquals("user1 new ID", list.getUser("user1 new ID").getLoginId());
		assertEquals("0", list.getUser("0").getLoginId());
		assertEquals(" ", list.getUser(" ").getLoginId());
		assertEquals("user4 new ID", list.getUser("user4 new ID").getLoginId());
		
		list.getUser("user1 new ID").setLoginId("1");
		list.getUser("0").setLoginId("2");
		list.getUser(" ").setLoginId("3");
		list.getUser("user4 new ID").setLoginId("4");
		
		assertEquals("1", list.getUser("1").getLoginId());
		assertEquals("2", list.getUser("2").getLoginId());
		assertEquals("3", list.getUser("3").getLoginId());
		assertEquals("4", list.getUser("4").getLoginId());
		
	}
	
	public void testChris3() {
		//Test method for getDisplayDescription() and setDisplayDescription() in Task
		
		Task task1 = new Task("Task 1 Display Description", "Task1 Location", "Task 1 Due Date", "Task 1 details", "Task 1 type", false);
		Task task2 = new Task("Task 2 Display Description", "Task2 Location", "Task 2 Due Date", "Task 2 details", "Task 2 type", false);
		Task task3 = new Task("Task 3 Display Description", "Task3 Location", "Task 3 Due Date", "Task 3 details", "Task 3 type", false);
		Task task4 = new Task("Task 4 Display Description", "Task4 Location", "Task 4 Due Date", "Task 4 details", "Task 4 type", false);
		
		assertEquals("Task 1 Display Description", task1.getDisplayDescription());
		assertEquals("Task 2 Display Description", task2.getDisplayDescription());
		assertEquals("Task 3 Display Description", task3.getDisplayDescription());
		assertEquals("Task 4 Display Description", task4.getDisplayDescription());
		
		task1.setDisplayDescription(" ");
		task2.setDisplayDescription(" ");
		task3.setDisplayDescription(" ");
		task4.setDisplayDescription(" ");
		
		assertEquals(" ", task1.getDisplayDescription());
		assertEquals(" ", task2.getDisplayDescription());
		assertEquals(" ", task3.getDisplayDescription());
		assertEquals(" ", task4.getDisplayDescription());
	}
	
	public void testChris4() {
		//Test method for getLocation() and setLocation() in Task
		
		Task task1 = new Task("Task 1 Display Description", "Task1 Location", "Task 1 Due Date", "Task 1 details", "Task 1 type", false);
		Task task2 = new Task("Task 2 Display Description", "Task2 Location", "Task 2 Due Date", "Task 2 details", "Task 2 type", false);
		Task task3 = new Task("Task 3 Display Description", "Task3 Location", "Task 3 Due Date", "Task 3 details", "Task 3 type", false);
		Task task4 = new Task("Task 4 Display Description", "Task4 Location", "Task 4 Due Date", "Task 4 details", "Task 4 type", false);
		
		assertEquals("Task1 Location", task1.getLocation());
		assertEquals("Task2 Location", task2.getLocation());
		assertEquals("Task3 Location", task3.getLocation());
		assertEquals("Task4 Location", task4.getLocation());
		
		task1.setLocation(" ");
		task2.setLocation(" ");
		task3.setLocation(" ");
		task4.setLocation(" ");
		
		assertEquals(" ", task1.getLocation());
		assertEquals(" ", task2.getLocation());
		assertEquals(" ", task3.getLocation());
		assertEquals(" ", task4.getLocation());
	}
	
	public void testDave1() {
		//Test for User.checkPassword
		UserList users = new UserList();
		String[] passwords = {"Hello","World","testing","check","password"};
		for(int i = 0; i < passwords.length; i++){
			try {
				users.addUser(new User(passwords[i], passwords[i], passwords[i], passwords[i]));
			} catch (Exception e) {
				
				e.printStackTrace();
			}
		}
		for(int i = 0; i < passwords.length; i++){
			assertTrue(users.getUser(passwords[i]).checkPassword(passwords[i]));
		}
	}
	
	public void testDave2() {
		//Test for TaskList.getStringTasks()
		TaskList tasks = new TaskList();
		String[] taskDescriptions = {"Hello","World","testing","get","string","tasks"};
		for(int i = 0; i < taskDescriptions.length; i++){
			try {
				tasks.addTask(new Task(taskDescriptions[i], "test", "test", "test", "test", false));
			} catch (Exception e) {
				
				e.printStackTrace();
			}
		}
		String[] results = tasks.getStringTasks(new Filter(null, null, true));
		assertTrue(results.length == taskDescriptions.length);
		for(int i = 0; i < taskDescriptions.length; i++){
			assertTrue(results[i].equals(taskDescriptions[i]));
		}
	}
	
	public void testDave3() {
		//Test method for getDueDate() and setDueDate() in Task
		
		Task task1 = new Task("Task 1 Display Description", "Task1 Location", "Task 1 Due Date", "Task 1 details", "Task 1 type", false);
		Task task2 = new Task("Task 2 Display Description", "Task2 Location", "Task 2 Due Date", "Task 2 details", "Task 2 type", false);
		Task task3 = new Task("Task 3 Display Description", "Task3 Location", "Task 3 Due Date", "Task 3 details", "Task 3 type", false);
		Task task4 = new Task("Task 4 Display Description", "Task4 Location", "Task 4 Due Date", "Task 4 details", "Task 4 type", false);
		
		assertEquals("Task 1 Due Date", task1.getDueDate());
		assertEquals("Task 2 Due Date", task2.getDueDate());
		assertEquals("Task 3 Due Date", task3.getDueDate());
		assertEquals("Task 4 Due Date", task4.getDueDate());
		
		task1.setDueDate(" ");
		task2.setDueDate(" ");
		task3.setDueDate(" ");
		task4.setDueDate(" ");
		
		assertEquals(" ", task1.getDueDate());
		assertEquals(" ", task2.getDueDate());
		assertEquals(" ", task3.getDueDate());
		assertEquals(" ", task4.getDueDate());
	}
	
	public void testDave4() {
		//Test method for getDetails() and setDetails() in Task
		
		Task task1 = new Task("Task 1 Display Description", "Task1 Location", "Task 1 Due Date", "Task 1 details", "Task 1 type", false);
		Task task2 = new Task("Task 2 Display Description", "Task2 Location", "Task 2 Due Date", "Task 2 details", "Task 2 type", false);
		Task task3 = new Task("Task 3 Display Description", "Task3 Location", "Task 3 Due Date", "Task 3 details", "Task 3 type", false);
		Task task4 = new Task("Task 4 Display Description", "Task4 Location", "Task 4 Due Date", "Task 4 details", "Task 4 type", false);
		
		assertEquals("Task 1 details", task1.getDetails());
		assertEquals("Task 2 details", task2.getDetails());
		assertEquals("Task 3 details", task3.getDetails());
		assertEquals("Task 4 details", task4.getDetails());
		
		task1.setDetails(" ");
		task2.setDetails(" ");
		task3.setDetails(" ");
		task4.setDetails(" ");
		
		assertEquals(" ", task1.getDetails());
		assertEquals(" ", task2.getDetails());
		assertEquals(" ", task3.getDetails());
		assertEquals(" ", task4.getDetails());
	}
	
	public void testMichael1() {
		//Testing Filter's matches(Task currentTask)
		//Whitebox testing
		Filter filt = new Filter(null, null, null);
		Task tas = new Task(null, null, null, null, null, false);
		assertTrue(filt.matches(tas));
		filt = new Filter("8", null, null);
		tas = new Task(null, null, "7", null, null, false);
		assertFalse(filt.matches(tas));
		tas = new Task(null, null, "9", null, null, false);
		assertTrue(filt.matches(tas));
		filt = new Filter("8", "category", true);
		tas = new Task(null, null, "8", null, "type", true);
		assertFalse(filt.matches(tas));
		tas = new Task(null, null, "8", null, "category", true);
		assertTrue(filt.matches(tas));
		tas = new Task(null, null, "8", null, "category", false);
		assertTrue(filt.matches(tas));
		
		//Blackbox testing
		filt = new Filter("04142012", "School", false);
		tas = new Task("Homework", "Dorm", "04142012", "CS2340 homework", "School", false);
		assertTrue(filt.matches(tas));
		filt = new Filter(null, "School", false);
		assertTrue(filt.matches(tas));
		filt = new Filter(null, "School", true);
		assertTrue(filt.matches(tas));
		filt = new Filter("04142012", "School", false);
		tas = new Task("Homework", "Dorm", "04132012", "CS2340 homework", "School", false);
		assertFalse(filt.matches(tas));
		tas = new Task("Homework", "Dorm", "04142012", "CS2340 homework", "School", true);
		assertFalse(filt.matches(tas));
	}
	
	public void testMichael2() throws Exception {
		//Testing UserList's getUser(String loginId)
		//Whitebox testing
		UserList userlist = new UserList();
		User person = new User("name", "email", "login", "password");
		assertEquals(null, userlist.getUser("login"));
		userlist.addUser(person);
		assertEquals(person, userlist.getUser("login"));
		assertEquals(null, userlist.getUser("notLoginID"));
		
		
		//Blackbox testing
		User person1 = new User("Dave", "dkearns", "davey", "12345");
		User person2 = new User("Andrew", "achanrasmi", "andy", "12345");
		User person3 = new User("Chris", "cantly", "chris", "12345");
		User person4 = new User("Michael", "cyao", "yao", "12345");
		userlist.addUser(person1);
		userlist.addUser(person2);
		userlist.addUser(person3);
		userlist.addUser(person4);
		assertEquals(person1, userlist.getUser("davey"));
		assertEquals(null, userlist.getUser("dovey"));
		assertEquals(person2, userlist.getUser("andy"));
		assertEquals(null, userlist.getUser("andi"));
		assertEquals(person3, userlist.getUser("chris"));
		assertEquals(null, userlist.getUser("chros"));
		assertEquals(person4, userlist.getUser("yao"));
		assertEquals(null, userlist.getUser("yoo"));
		
	}
	
	public void testMichael3() {
		//Test Filter getStartDate() and setStartDate()
		Filter filt = new Filter(null, null, null);
		assertEquals(null, filt.getStartDate());
		filt.setStartDate("day");
		assertEquals("day", filt.getStartDate());
		filt.setStartDate("onemoretest");
		assertEquals("onemoretest", filt.getStartDate());
	}
	
	public void testMichael4() {
		//Test Task getDueDate() and setDueDate()
		Task assignment = new Task(null, null, null, null, null, null);
		assertEquals(null, assignment.getDueDate());
		assignment.setDueDate("due");
		assertEquals("due", assignment.getDueDate());
		assignment.setDueDate("a day");
		assertEquals("a day", assignment.getDueDate());
		
	}
}
